<template>
  <el-container class="home-container">
    <el-header>
      <div>
        <img src="../assets/lmy/seven4.jpg" class="avatar">
        <span>赖美云后援站</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container :style="{height:containerHeight}">
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-flag" @click="toggleflag">|||</div>
        <!-- unique-opened只能展开一个 -->
        <el-menu background-color="#333744" text-color="#fff" active-text-color="#409EFF" unique-opened :collapse="isCollapse" :collapse-transition='false' router default-active="">
          <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
            <template slot="title">
              <i :class="iconsObj[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>
            <!-- 二级菜单 -->
           
            <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id">
               <template slot="title">
                <!-- 图标 -->
                <i class="el-icon-menu"></i>
                <!-- 文本 -->
                <span>{{subItem.authName}}</span>
              </template>
            </el-menu-item>
       
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧主题内容 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>


<script>
export default {
  data() {
    //获取到的左侧从菜单数据
    return {
      menuList: [],
       iconsObj: {
        '125': 'iconfont icon-user',
        '103': 'iconfont icon-tijikongjian',
        '101': 'iconfont icon-shangpin',
        '102': 'iconfont icon-danju',
        '145': 'iconfont icon-baobiao'
      },
      isCollapse : false,
      containerHeight: '565px'
    };
  },
  created() {
    this.getMenuList();
  },
  mounted(){
    this.containerHeight = window.innerHeight - 60 + 'px'
    
    
  },
  methods: {
    logout() {  
        this.$confirm('你确定要离开可爱的小七了吗', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          window.sessionStorage.clear();
          this.$router.push("/login");
          this.$message.success("退出成功，小七在这里等你回来！QAQ");      
        
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消退出，小七爱你哦'
          });          
        });
      },
        async getMenuList() {
      const { data: res } = await this.$http.get("menus");
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.menuList = res.data;
      console.log(res);
    },
    toggleflag(){
      this.isCollapse = !this.isCollapse
    }
    
  },
   
    // },
    //获取所有的菜单
   
  };

</script>

<style lang="less" scoped>
.avatar{
    width:60px;
    height: 58px;
    border-radius: 50%;
}
.home-container {
  height: 100%;
  .el-container {
    height: 100%;
  }
}
.el-header {
  background-color: #373d41;
  padding-left: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  div {
    display: flex;
    align-items: center;
    img {
      margin-right: 20px;
    }
    span {
      font-size: 20px;
      font-weight: 600;
    }
  }
}
.el-aside {
  background-color: rgb(51, 55, 68);
  .el-menu {
    border: 0;
  }
}
.el-main{
    background: url('../assets/seven.jpg')
}
.iconfont {
  margin-right: 10px;
}
.toggle-flag {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>